<template>
  <div>
    <van-nav-bar title="面经登录"></van-nav-bar>
    <user-form @onSubmit="onSubmit">
      <template #btn>
        <van-button color="#ff7d00" block type="info" native-type="submit">
          登录
        </van-button>
      </template>
      <template #link>
        <router-link to="/register">注册账号</router-link>
      </template>
    </user-form>
  </div>
</template>

<script>
import { loginAPI } from "@/api/user";
import UserForm from "../components/UserForm.vue";
// 2. 导入
import { setToken } from "../utils/storage";

export default {
  components: {
    UserForm,
  },
  methods: {
    async onSubmit(values) {
      const res = await loginAPI(values);

      // 3. 使用setToken存token
      setToken(res.data.token);
      this.$toast("登录成功");
      this.$router.push("/");
    },
  },
};
</script>

<style lang="less"></style>
